<template>
	<view>
		<view v-for="(n,index) in curse.curseCount" :key="index">
			<text style="display: inline-block;">第{{n+1}}节课</text>
			<text v-if="!isEdit[n]" style="margin-left: 60%;text-decoration:underline;display: inline-block;" @tap="toEdit(n)">编辑</text>
				<image v-if="isEdit[n]" style="margin-left: 60%;height: 40rpx;width: 40rpx;display: inline-block;background-color: #FFFFFF;" src="/static/ok.png"></image>
			<view style="height: 50rpx;"></view>
		</view>
	<button class="btn-bottom" type="primary" @click="complete()">完成</button>
	</view>
</template>

<script>
	import base from '@/common/base.js'
	export default {
		data() {
			return {
				curse:[],
				path:"/pages/user/course/editEachCourse",
				isEdit:base.isEditArr
			}
		},
		onLoad(options) {
			this.getCurse(options.curseId,options.index);
		},
		onBackPress() {
			uni.request({
				url:base.urlPrefix+'yoga_app/curse/deleteCurseById',
				data:{
					curseId:this.curse.curseId
				}
			})
		},
		methods:{
			getCurse(curseId,index){
				uni.request({
					url:base.urlPrefix+'yoga_app/curse/getCurseById',
					data:{
						curseId:curseId
					},
					success: (res) => {
						this.curse=res.data.object;
						this.initIsEditArr(index);
					}
				})
			},
			toEdit(index){
				uni.navigateTo({
					url:"/pages/user/course/editEachCourse?curseId="+this.curse.curseId+"&index="+index
				})
			},
			initIsEditArr(index){
				if(index==-1){
					for(let i=0;i<this.curse.curseCount;i++){
						base.isEditArr[i]=false;
					}
				}else{
					base.isEditArr[index]=true;
				}
			},
			complete(){
				let isCompleted=true;
				for(let i=0;i<base.isEditArr.length;i++){
					if(base.isEditArr[i]==false){
						isCompleted=false;
						break;
					}
				}
				if(isCompleted==true){
					uni.request({
						url:base.urlPrefix+'yoga_app/curse/coachSubmitCurseRequest',
						data:{
							curseId:this.curse.curseId
						}
					})
					uni.showToast({
						title:'课程上传成功',
						icon:'success'
					});
					setInterval(function(){
						
					},1000);
					uni.switchTab({
						url:"/pages/tabBar/user/user",
					});
				}else{
					uni.showToast({
						title:'课程信息尚未填写完成',
						icon:'none'
					});
				}
			}
		}
	}
</script>

<style>
	.inp {
		display: flex;
		align-items: center;
		height: 50rpx;
		padding: 12rpx 13rpx;
		border-radius: 5rpx;
	}
	.input-label{
		background-color: #A7A7A7;
	}
	.bottom{
		margin-bottom: 0rpx;
	}
	.btn-bottom{
		margin-bottom: 0rpx;
		margin-right: 0rpx;
	}
</style>
